<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/11/1
  Time: 12:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../include/head.jsp">
    <jsp:param name="title" value="Gateway状态"/>
</jsp:include>

<jsp:include page="../include/admin_header.jsp"/>

<jsp:include page="../include/admin_sidebar.jsp"/>
<div class="content-wrapper content-wrapper-bg">
    <section class="content-header">
        <h4 class="page-title" style="display: inline-block"><spring:message code="label.admin.gateway.state"/></h4>

        <div class="sie-search-parent">
            <input type="text" placeholder="<spring:message code="label.admin.search"/>" class="form-control sie-search-input" id="inputSuccess2">
            <img src="/images/search.png" class="sie-search-img"/>
        </div>
    </section>
    <section class="content">
        <div class="box box-primary table-header-line">
            <div class="box-body" style="padding: 0">
                <table class="table" id="user_list">
                    <thead>
                    <tr>
                        <th><spring:message code="label.sequence.number"/></th>
                        <th><spring:message code="label.name"/></th>
                        <th><spring:message code="label.version"/></th>
                        <th><spring:message code="label.current.state"/></th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
        <%--</div>--%>
    </section>
</div>
<jsp:include page="../include/foot.jsp"/>
<script>
    $(document).ready(function () {
        var options = {
            "dom": '<"datatable-header"<"dataTables_filter">l><"datatable-scroll"t><"datatable-footer dataTable-footer-padding"<"pull-left"i><"pull-right"p>>',
            paging: true,
            lengthChange: false,
            ordering: true,
            autoWidth: false,
            info: true,
            serverSide: true,
            fixedHeader: true,
            searching: true,
            aLengthMenu: [15],
            ajax: {
                url: '/admin/api/v1/device/gatewayState',
                dataSrc: 'data'
            },
            columns: [
                {
                    data: null
                },
                {
                    data: 'clientId'
                },
                {
                    data: 'version'
                },
                {
                    data: 'time',
                    "render": function (data, type, full, meta) {
                        var now = new Date().getTime();
                        if ((now-data)/1000<15){
                            return "ONLINE";
                        }else{
                            return "OFFLINE";
                        }
                    }
                }
            ]
        };
        var uri = window.location.href;
        console.log(uri);
        if (!(uri.indexOf("lang=en")>0)) {
            options["language"]={url: '/lang/datatable.chs.json'};
        }
        var table = $('#user_list').DataTable(options);
        $('#inputSuccess2').bind('keyup', function () {
            table.search(this.value).draw();
        });

        table.on('draw.dt', function () {
            table.column(0, {
                search: 'applied',
                order: 'applied'
            }).nodes().each(function (cell, i) {
                cell.innerHTML = i + 1;
            });
        });
    });
</script>